1. Field of the Invention
The present invention generally relates to the field of data processing and, more particularly, to program execution by means of multiple threads.
2. Background of the Invention
In a multi-thread environment, the memory address space for global data is usually shared among the threads. In addition, the threads require storage of thread private data in dedicated data areas of respective stacks.
For example, the data used in a program written in the programming language C can be classified into two categories: global variables and auto variables. In these two categories, the global variables, which correspond to the global data to be shared among the threads in the above described model, are usually allocated in the data space as they are to be accessible from a plurality of functions. In contrast, the auto variables are usually allocated on the stacks, as they are declared within a function and valid only within that function.
In a multi-thread environment, it is often necessary to employ a data management method for supporting thread private data on a per thread basis. Conventionally, the following two methods have been proposed for this purpose.
(I) Method for Allocating Private Data on Stack Dynamically:
In this method, thread private data is allocated on the stack by declaring data used in several functions as auto variables in a certain function that is executed by each thread. Here, however, when the allocated data is to be used in other functions than the function that declared the auto variable, it is not possible for the other functions to directly access the allocated auto variables. Therefore, there arises a need for handing the address of the allocated variable as a function argument from the calling function to that called function.
Thus, in this conventional data management method for supporting private data for each thread, there is a need to pass the address of the private data as a function argument when calling one function from another function. Thus, the program entry for the called function that operates on the private data must contain the argument specifying the address of the private data and, consequently, the program becomes quite complicated. In addition, in the called function, there is a need to store the address of the private data on the stack.
(II) Method for Expanding Variables in Correspondence to Multiple Threads, and Accessing Variables by Using Thread Identifiers (IDs):
In this method, each part of the thread private data is globally declared as a global sequence having as many elements as there are threads. An access from each thread is made by using a thread ID which is uniquely assigned to each thread in advance. In this method, if the thread IDs are not supported at the OS level, it becomes necessary to support the thread IDs themselves by using the specialized method (I) described above. Moreover, even when the thread IDs are supported at the OS level, this method is not applicable to a case in which the number of threads changes dynamically. Thus, in this conventional data management method for supporting the global data privately by each thread, there is a need to provide the thread IDs.
U.S. Pat. No. 5,511,192 shows a specific method of managing thread private data in which the thread private data can be declared globally and which can deal with the change of the number of threads. The thread private data, to be globally accessible from the multiple threads and to be managed separately by each one of the multiple threads, is detected before the actual execution of the program, and a thread private data region for managing all the detected thread private data is allocated to the stack for each one of the multiple threads separately.
Then, a pointer to specify a base address of the thread private data region with respect to the stack for each one of the multiple threads is registered separately, such that while executing one of the multiple threads, accesses to the thread private data are made by making accesses to the thread private data region in the stack for that one of the multiple threads according to the base address specified by the pointer registered for that one of the multiple threads.